package com.linyaonan.leetcode.easy._2379;

/**
 * @author: Lin
 * @date: 2024/10/7
 */
public class MinimumRecolors {

    public int minimumRecolors(String blocks, int k) {
        int min = k;
        int add = 0;
        int p = 0;
        for (int i = 0; i < blocks.length(); i++) {
            char c = blocks.charAt(i);
            // 等于白色需要涂改成黑色
            if (c == 'W') {
                p++;
            }
            add++;
            // 等于目标长度后计算涂黑的个数
            if (add == k) {
                min = Math.min(min, p);
                p -= blocks.charAt(i - k + 1) == 'W' ? 1 : 0;
                add--;
            }
        }
        return min;
    }

}
